package com.su.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.su.gulimall.order.service.OrderService;
import com.su.gulimall.order.utils.AlipayTemplate;
import com.su.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class PayWebContrloller {
    @Autowired
    AlipayTemplate alipayTemplate;
    @Autowired
    OrderService orderService;
    //产生的是一个页面，而不是一个json数据
    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);
        String result = alipayTemplate.pay(payVo);
        return result;
    }
}
